<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
      name="viewport">
<link type="text/css" rel="stylesheet" href="../addons/{php echo $this->modulename}/template/mobile/css/bootstrap.min.css">
<script type="text/javascript" src="../addons/{php echo $this->modulename}/template/mobile/js/jquery-1.7.2.min.js"></script>
<title>{$rule['stitle']}</title>
<style>
*{
	margin: 0;
	padding: 0;
}
.userinfo{
	width: 80%;
	left: 10%;
	margin-top: 25%;
	z-index: 100;
	position: absolute;
	display: none;
}

.userinfo label{
	width: 50px;
}

.userinfo input{
	display: inline-block;width: 60%;
}

.userinfo textarea{
	display: inline-block;width: 60%;
}

.userinfo .form-group{
	margin-bottom: 5px;
}

.users{
	width:30%;
	display: inline-block;
	text-align: center;
}

th{
	text-align: center !important;
	vertical-align: middle !important;
}
td{
	text-align: center !important;
	vertical-align: middle !important;
}
</style>
</head>
<body>
{template 'common'}
{if empty($player)}
<div style="text-align: center;position: absolute;left: 40%;top: 60%;"><a class="btn btn-default" onclick="onBegin()">搭建鹊桥</a></div>
{/if}
{if !empty($player['myname'])}
<div style="text-align: center;position: absolute;top: 60%;width: 60%;left: 20%;">
{if $player['status'] == 0}<a class="btn btn-warning" style="width: 100%;" onclick="$('#share').show()">邀请好友获取祝福喜鹊</a>{/if}
{if $award}<a class="btn btn-info" style="width: 100%;" onclick="$('#award').show()">我的奖品</a>{/if}
{if $rule['rank'] > 0}<a class="btn btn-success" style="width: 100%;margin-top: 5px;" onclick="$('#rank').show()">鹊桥搭建排行榜</a>{/if}
</div>
<div style="position: absolute;right: 5px;top: 5px;color: orange;font-weight: bold;"><label>我的喜鹊：</label> {$count}/{$rule['birds_success']}</div>

{/if}
{if $player && !$player['myname']}
<div class="panel panel-danger" style="width: 80%;position: absolute;left: 10%;top: 25%;" id="niulangzhinv">
<div class="panel-heading" style="padding: 0 15px;text-align: center;">设置你的牛郎织女</div>
	<div class="panel-body" style="padding: 15px 0;">
		<div class="form-group" style="text-align: center;">
			 <label style="width: 30%;">牛郎 </label><font style="color: red;"> ————— </font><label style="width: 30%;"> 织女</label>
			 <div><input id="niulang" class="form-control users" placeholder="牛郎" maxlength="6"><font style="color: red;"> ————— </font><input maxlength="6" id="zhinv" class="form-control users" placeholder="织女"></div>
		</div>
		<div style="text-align: center;"><button class="btn btn-primary btn-sm" onclick="onSaveUser()">保存</button></div>
	</div>
</div>
{/if}

<div id="award" class="panel panel-info" style="width: 80%;position: absolute;left: 10%;top: 20%;display: none;" onclick="$(this).hide()">
<div class="panel-heading" style="padding: 0 15px;text-align: center;">中奖信息</div>
	<div class="panel-body" style="padding: 15px 0;text-align: center;overflow: scroll;max-height: 280px;">
		<b style="display: block;color: orangered;">恭喜你！获得以下奖品</b>
		<b style="display: block;">{$prize['title']}{if $player['status']==2}<label style="color: green;">(已发奖)</label>{/if}</b>
		<img src="{php echo toimage($prize['thumb'])}" style="width: 100%;padding: 3px 10px;">
		<div>{$prize['description']}</div>
	</div>
</div>
<div id="rank" class="panel panel-success" style="width: 80%;position: absolute;left: 10%;top: 20%;display: none;" onclick="$(this).hide()">
<div class="panel-heading" style="padding: 0 15px;text-align: center;">鹊桥搭建排行榜</div>
	<div class="panel-body" style="padding: 0;text-align: center;overflow-y: scroll;max-height: 280px;">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width: 20%;">排名</th>
					<th>参与者</th>
					<th>喜鹊数</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $k $l}
				<tr>
					<td>{php echo $k+1}</td>
					<td><img src="{$l['avatar']}" style="width: 30px;height: 30px;"> <b>{$l['nickname']}</b></td>
					<td>{if !$l['bnum']}0{else}{$l['bnum']}{/if}</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		
	</div>
</div>

<div class="panel panel-default userinfo">
	<div class="panel-heading" style="padding: 0 15px;text-align: center;">个人信息</div>
	<div class="panel-body" style="padding: 15px 0;">
		<form action="{php echo $this->createMobileUrl('info',array('rid'=>$rule['rid']))}" method="post" onsubmit="return checksubmit(this)">
			<p style="font-size: 12px;font-weight: bold;padding: 0 15px;">{$rule['awardtips']}</p>
			{if $rule['isrealname']}
			<div class="form-group" style="text-align: center;">
			     <label>姓名：</label><input  type="text" value="" name="realname" class="form-control">
			</div>
			{/if}
			{if $rule['ismobile']}
			<div class="form-group" style="text-align: center;">
			     <label>手机：</label><input  type="tel" value="" maxlength="11" name="mobile" class="form-control">
			</div>
			{/if}
			{if $rule['isqq']}
			<div class="form-group" style="text-align: center;">
			     <label>QQ：</label><input  type="tel" value="" name="qq" class="form-control">
			</div>
			{/if}
			{if $rule['isemail']}
			<div class="form-group" style="text-align: center;">
			     <label>邮箱：</label><input  type="text" value="" name="email" class="form-control">
			</div>
			{/if}
			{if $rule['isaddress']}
			<div class="form-group" style="text-align: center;">
			     <label>地址：</label><textarea id="address" style="vertical-align: middle;" name="address" class="form-control"></textarea>
			</div>
			{/if} 
			<div style="text-align: center;"><button type="submit" class="btn btn-primary">提交</button></div>
		</form>
	</div>
</div>

<div id="share" onclick="$(this).hide()" style="display:none;position: fixed;top:0;background: rgba(0,0,0,.5);width: 100%;height: 100%;z-index: 100;text-align: right;">
	<img  src="../addons/{php echo $this->modulename}/template/mobile/img/share.png">
</div>
<script>

var time = 1;
function checksubmit(obj){
	if(time == 1) time++;
	else return;
	var inputs = $(obj).find('input');
	for(var i = 0;i < inputs.length; i++ ){
		if($.trim(inputs.eq(i).val()) == ''){
			alert('请完善您的信息！');
			return false;
		}
	}
	if($('#address').length > 0 && $.trim($('#address').val()) == ''){
		alert('请完善您的信息！');
		return false;
	}
}

function onSaveUser(){
	if(confirm('保存后将不能修改哦！确定保存吗？')){
		$.ajax({
			url: '{php echo $this->createMobileUrl("info",array("op"=>"user","rid"=>$rid))}',
			type:'post',
			dataType:'json',
			data:{nl:$('#niulang').val(),zn:$('#zhinv').val()},
			success:function(msg){
				if(msg == "1"){
					$('#myname').val($('#niulang').val());
					$('#hname').val($('#zhinv').val());
					location.reload();
				}else{
					alert('保存失败，请重试');
					location.reload();
				}
			},
			error:function(msg){
				alert('发送请求失败，请重试');
				location.reload();
			},
		});
	}
}
function onBegin(){
	{if $rule['starttime'] > time()}
		alert('很抱歉，该活动还未开始！');
		return;
	{/if}
	{if $rule['endtime'] <= time()}
		alert('很抱歉，该活动已经结束！');
		return;
	{/if}
	{if empty($rule['describe_limit']) && !$follow}
	{php $url = $this->module['config']['describeurl'];}
		{if empty($url)}
			$('#describe').show();
			return;
		{else}
			alert('请先关注公众号！');
			location.href='{$url}';	
			return;
		{/if}
	{/if}
	$('.userinfo').show();
}
</script>
{if !empty($player['myname'])}
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js?v=20150120"></script>
<script type="text/javascript">
	{php $signPackage = $_W['account']['jssdkconfig']}
    wx.config({
	    debug: false,
	    appId: "{$signPackage['appId']}",
	    timestamp: "{$signPackage['timestamp']}", 
	    nonceStr: "{$signPackage['nonceStr']}", 
	    signature: "{$signPackage['signature']}",
	    jsApiList: [
	        'checkJsApi',
	        'onMenuShareTimeline',
	        'onMenuShareAppMessage',
	        'onMenuShareQQ',
	        'onMenuShareWeibo'
	     ]
	});
        var shareData = {
        	      title: "{$rule['sharetitle']}",
        	      link: "{php echo $_W['siteroot']."app".substr($this->createMobileUrl('share',array('pid'=>$openid,'rid'=>$rid)),1)}",
        	      desc: '{$rule["sharedesc"]}',
        	      imgUrl: "{php echo toimage($rule['sharethumb'])}"
        	    };

        	wx.ready(function () {
        	    wx.onMenuShareAppMessage(shareData);
        	    wx.onMenuShareTimeline(shareData);
        	    wx.onMenuShareQQ(shareData);
        	    wx.onMenuShareWeibo(shareData);
        	});
</script>
{/if}
</body>
</html>